﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using LowLevelGraphics.CustomControls;
using LowLevelGraphics;
using LowLevelGraphics.Filter;
using LowLevelGraphics.ColorSpaces;

namespace ImageRecognition2.Forms
{
    public partial class FormChannelMath : Form, IFormFilter
    {
        private int[] m_aChannel = new int[2];

        private Image m_ImageOriginal;
        public FormChannelMath()
        {
            InitializeComponent();
            foreach (AbstractColorSpace colorSpace in Definitions.ColorSpaces)
            {
                this.cobColorSpace.Items.Add(new ColorSpaceItem(colorSpace));
            }
            this.cobColorSpace.SelectedIndex = 0;
            ReInitializeChannelRadioButtons();
        }

        private List<RadioButton> m_aRadioButton = new List<RadioButton>();

        private void ReInitializeChannelRadioButtons()
        {
            for (int i = 0; i < m_aRadioButton.Count; i++)
            {
                this.gbChannel.Controls.Remove(m_aRadioButton[i]);
            }
            m_aRadioButton.Clear();

            this.cobColorSpace.SelectedIndex = 0;
            int nChannelCount = ((ColorSpaceItem)this.cobColorSpace.SelectedItem).ColorSpace.GetValues().Length;

            int nWidth = 30;
            int nHeight = 30;
            int nX = 10;
            int nY = 0;

            for (int i = 0; i < nChannelCount; i++)
            {
                RadioButton radioButton = new RadioButton();

                radioButton.Size = new Size(nWidth, nHeight);
                radioButton.Location = new Point(nX + nWidth * i, nY);
                radioButton.Text = i.ToString();
                radioButton.Parent = this.groupBox1;

                this.m_aRadioButton.Add(radioButton);

                radioButton = new RadioButton();
                radioButton.Size = new Size(nWidth, nHeight);
                radioButton.Location = new Point(nX + nWidth * i, nY);
                radioButton.Text = i.ToString();
                radioButton.Parent = this.groupBox2;

                this.m_aRadioButton.Add(radioButton);
            }
        }

        private void cobColorSpace_SelectedIndexChanged(object sender, EventArgs e)
        {
            ReInitializeChannelRadioButtons();
        }

        public Image imgOriginal
        {
            get { return m_ImageOriginal; }
            set { m_ImageOriginal = value; }
        }

        public SelectablePictureBox PictureBox
        {
            get { return pbNew; }
        }
    } 
}
